using System.IO;

namespace BitTorrent.Client.Peer.Message.Standard {
    internal class Port : PeerMessage {
        public Port(BinaryReader reader) {
            Value = ReadShort(reader);
        }

        /// <summary>
        /// Gets or sets the port value.
        /// </summary>
        /// <value>The value.</value>
        public short Value { get; set; }

        public override byte[] GetMessage() {
            var message = new byte[3];

            using (var stream = new MemoryStream(message)) {
                var writer = new BinaryWriter(stream);
                writer.Write(ToBytes(3));
                writer.Write((byte)PeerMessageId.Port);
                writer.Write(ToBytes(Value));
            }

            return message;
        }
    }
}